package com.wv.api.server.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.wv.api.server.common.BaseController;
import com.wv.api.service.ISysRoleService;
import com.wv.common.result.Result;
import com.wv.model.system.SysRole;
import com.wv.model.system.condition.SysRoleCondition;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
@Api(tags = "角色管理相关接口")
public class SysRoleController extends BaseController {

    @Autowired
    private ISysRoleService sysRoleService;

    @PostMapping("list")
    @ApiOperation(value = "分页查询")
    @SaCheckPermission("role:list")
    public Result list(@RequestBody SysRoleCondition sysRoleCondition){
        return sysRoleService.findPageList(sysRoleCondition);
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询所有角色")
    @SaCheckPermission("role:list")
    public Result all(){
        return sysRoleService.findAll();
    }

    @PostMapping
    @ApiOperation(value = "新增角色")
    @SaCheckPermission("role:add")
    public Result save(@RequestBody SysRole role){
        return sysRoleService.add(role);
    }

    @PutMapping
    @ApiOperation(value = "修改角色")
    @SaCheckPermission("role:update")
    public Result update(@RequestBody SysRole role){
        return sysRoleService.update(role);
    }

    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除角色")
    @SaCheckPermission("role:delete")
    public Result delete(@PathVariable("ids") String[] ids){
        return sysRoleService.remove(ids);
    }


}
